package com.edu.kindergarten.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.edu.kindergarten.R;
import com.edu.kindergarten.entity.SuggestionEntity;
import com.edu.kindergarten.utils.LogUtils;
import com.edu.kindergarten.utils.UiUtils;


public class SuggestionListAdapter extends BaseAdapter {

	private static final String TAG = "SuggestionListAdapter";

	private Context context;
	private int layoutId;
	private List<SuggestionEntity> listData;
	private int to[];
	
	public SuggestionListAdapter(Context context, int layoutId,
			List<SuggestionEntity> listData, int to[]) {
		this.context = context;
		this.layoutId = layoutId;
		this.listData = listData;
		this.to = to;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		LogUtils.d(TAG, "constructor,listData size:" + listData.size());
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		LogUtils.d(TAG, "getView,position=" + position);

		if (convertView == null) {
			LogUtils.d(TAG, "yangsir convertView is null !! position=" + position);
			LayoutInflater layoutInflator = LayoutInflater.from(context);
			convertView = layoutInflator.inflate(layoutId,parent,false);
			holder = new ViewHolder();

			holder.status_img = (ImageView) convertView.findViewById(to[0]);
			holder.status_text = (TextView) convertView.findViewById(to[1]);
			holder.theme = (TextView) convertView.findViewById(to[2]);
			holder.date = (TextView) convertView.findViewById(to[3]);
			holder.content = (TextView) convertView.findViewById(to[4]);
			
			convertView.setTag(holder);
		}else {
			LogUtils.d(TAG, "yangsir convertView is not null ! position=" + position);
			holder = (ViewHolder) convertView.getTag();
		}
		
		LogUtils.d(TAG, "yangsir position=" + position + "status_text"+listData.get(position).getStatus_text());
		holder.status_img.setImageResource(listData.get(position).getStatus_img());
		holder.status_text.setText(listData.get(position).getStatus_text());
		holder.theme.setText(listData.get(position).getTheme());
		holder.date.setText(listData.get(position).getDate());
		holder.content.setText(listData.get(position).getContent());
		
		return convertView;
	}

	static class ViewHolder {
		 ImageView status_img;
		 TextView status_text;
		 TextView theme;
		 TextView date;
		 TextView content;	
	}

}
